{template 'common/header'}
{template 'common'}
<ul class="nav nav-tabs">
    <li {if $operation=='display'} class="active" {/if}>
    <a href="{php echo $this->createWebUrl('line',array('op' =>'display'))}">线路列表</a>
    </li>
    <li {if empty($line['id']) && $operation == 'post'} class="active" {/if}>
    <a href="{php echo $this->createWebUrl('line',array('op' =>'post'))}">添加线路</a>
    </li>
    {if !empty($line['id']) && $operation == 'post'}
    <li class="active">
        <a href="{php echo $this->createWebUrl('line',array('op' =>'post','id'=>$line['id']))}">编辑线路</a>
    </li>
    {/if}
</ul>

<!--列表-->
{if $operation == 'display'}
<div class="main panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead class="navbar-inner">
            <tr>
                <th style="width:30px;">ID</th>
                <th>显示顺序</th>
                <th>缩略图</th>
                <th>名称</th>
                <th>标签</th>
                <th>单价</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {loop $list $line}
            <tr>
                <td>{$line['id']}</td>
                <td>{$line['sort']}</td>
                <td>
                    <img src="{php echo tomedia($line['thumb'])}" alt="{$line['name']}" width="40">
                </td>
                <td>{$line['name']}</td>
                <td>{$line['label']}</td>
                <td>{$line['price']}</td>
                <td style="text-align:left;">
                    <a href="{php echo $this->createWebUrl('line', array('op' => 'post', 'id' => $line['id']))}"
                       class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="修改">
                        <i class="fa fa-edit"></i>
                    </a>
                    <a href="{php echo $this->createWebUrl('line', array('op' => 'delete', 'id' => $line['id']))}"
                       class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="删除">
                        <i class="fa fa-times"></i>
                    </a>
                </td>
            </tr>
            {/loop}
            </tbody>
        </table>
        {$pager}
    </div>`
</div>
<script>
    require(['bootstrap'], function ($) {
        $('.btn').hover(function () {
            $(this).tooltip('show');
        }, function () {
            $(this).tooltip('hide');
        });
    });
</script>

<!--增加修改-->
{elseif $operation == 'post'}
<div class="main">
    <form id="form1" action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{$line['id']}"/>
        <div class="panel panel-default">
            <div class="panel-heading">
                线路设置
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="number" name="sort" class="form-control" value="{$line['sort']}"/>
                        <span class="help-block">请输入0~255，越大越前</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label" for="name">
                        <span style="color:red">*</span>
                        线路名称
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='name' name="name" class="form-control" value="{$line['name']}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label" for="price">
                        <span style="color:red">*</span>
                        单价
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="number" id='price' name="line_price" class="form-control" value="{$line['price']}"/>
                        <!--                         <span class="help-block">RMB</span>
                         -->                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label" for="tag">
                        <span style="color:red">*</span>
                        推荐标签
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='label' name="label" class="form-control" value="{$line['label']}"/>
                        <span class="help-block">如:极光精选</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label" for="tag">
                        <span style="color:red">*</span>
                        详细标签
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='tag' name="tag" class="form-control" value="{$line['tag']}"/>
                        <span class="help-block">多个,号分割</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        <span style="color:red">*</span>
                        线路缩略图
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_form_field_image('thumb', $line['thumb'])}
                        <span class="help-block">图片280*144px</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        <span style="color:red">*</span>
                        线路展示图
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_form_field_multi_image('thumbs', $line['thumbs'])}
                        <span class="help-block">图片730*350px</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        绑定酒店
                    </label>
                    <div class="col-sm-8 col-xs-12">
                        {loop $hotels $hotel}
                        <div class="col-sm-3">
                            <div class="checkbox">
                                <input type="checkbox" {php if(in_array($hotel['id'],$line_hotel_array))echo 'checked'; } value="{$hotel['id']}" name="hotels[]">
                                {$hotel['name']}
                            </div>
                        </div>
                        {/loop}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        线路描述
                    </label>
                    <div class="col-sm-8 col-xs-12">
                        <textarea style="height:80px;" class="form-control" id="introduction" name="introduction"
                                  cols="70">{$line['introduction']}</textarea>
                        <span class="help-block">不超过100字</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        线路备注
                    </label>
                    <div class="col-sm-8 col-xs-12">
                        <textarea style="height:80px;" class="form-control" id="remark" name="remark"
                                  cols="70">{$line['remark']}</textarea>
                        <span class="help-block">不超过100字</span>
                    </div>
                </div>

            </div>
        </div>

        <div class="panel panel-default">
            <div class="panel-heading">
                产品介绍
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        <span style="color:red">*</span>
                        标题
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="product[title]" class="form-control" value="{$line['product_desc']['title']}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        描述
                    </label>
                    <div class="col-sm-8 col-xs-12">
                        <textarea style="height:100px;" class="form-control" name="product[desc]"
                                  cols="100">{$line['product_desc']['desc']}</textarea>
                    </div>
                </div>
                {loop $line['product_desc']['trip'] $index $trip}
                <div class="form-group" id="product_title_{$index}">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        行程标题
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="product[trip][{$index}][trip_title]" class="form-control" value="{$trip['trip_title']}"/>
                    </div>
                </div>
                <div class="form-group" id="product_desc_{$index}">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        行程描述
                    </label>
                    <div class="col-sm-8 col-xs-12">
                        <textarea style="height:100px;" class="form-control" name="product[trip][{$index}][trip_desc]"
                                  cols="100">{$trip['trip_desc']}</textarea>
                    </div>
                </div>
                <div class="form-group col-sm-12" id="product_button_{$index}">
                    <button class="btn btn-danger col-sm-offset-2" type="button" onclick="delProduct('{$index}');">
                        删除行程
                    </button>
                </div>
                {/loop}
                <div class="form-group col-sm-12" id="addProduct">
                    <button class="btn btn-info col-lg-1 pull-right" type="button" onclick="addProduct();">
                        添加
                    </button>
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                费用说明
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        <span style="color:red">*</span>
                        标题
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="price[title]" class="form-control" value="{$line['price_desc']['title']}"/>
                    </div>
                </div>
                {loop $line['price_desc']['price'] $index $price}
                <div class="form-group" id="price_title_{$index}">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        费用标题
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="price[price][{$index}][price_title]" class="form-control" value="{$price['price_title']}"/>
                    </div>
                </div>
                <div class="form-group" id="price_desc_{$index}">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        费用描述
                    </label>
                    <div class="col-sm-8 col-xs-12">
                        <textarea style="height:100px;" class="form-control" name="price[price][{$index}][price_desc]"
                                  cols="100">{$price['price_desc']}</textarea>
                    </div>
                </div>
                <div class="form-group col-sm-12" id="price_button_{$index}">
                    <button class="btn btn-danger col-sm-offset-2" type="button" onclick="delPrice('{$index}');">
                        删除费用
                    </button>
                </div>
                {/loop}
                <div class="form-group col-sm-12" id="addPrice">
                    <button class="btn btn-info col-lg-1 pull-right" type="button" onclick="addPrice();">
                        添加
                    </button>
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                购买须知
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        <span style="color:red">*</span>
                        标题
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="buy[title]" class="form-control" value="{$line['buy_desc']['title']}"/>
                    </div>
                </div>
                {loop $line['buy_desc']['buy'] $index $buy}
                <div class="form-group" id="buy_title_{$index}">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        购买标题
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="buy[buy][{$index}][buy_title]" class="form-control" value="{$buy['buy_title']}"/>
                    </div>
                </div>
                <div class="form-group" id="buy_desc_{$index}">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        购买描述
                    </label>
                    <div class="col-sm-8 col-xs-12">
                        <textarea style="height:100px;" class="form-control" name="buy[buy][{$index}][buy_desc]"
                                  cols="100">{$buy['buy_desc']}</textarea>
                    </div>
                </div>
                <div class="form-group col-sm-12" id="buy_button_{$index}">
                    <button class="btn btn-danger col-sm-offset-2" type="button" onclick="delBuy('{$index}');">
                        删除购买
                    </button>
                </div>
                {/loop}
                <div class="form-group col-sm-12" id="addBuy">
                    <button class="btn btn-info col-lg-1 pull-right" type="button" onclick="addBuy();">
                        添加
                    </button>
                </div>
            </div>
        </div>

        <div class="form-group col-sm-12">
            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"/>
            <input type="hidden" name="token" value="{$_W['token']}"/>
        </div>
    </form>
</div>

<script language='javascript'>
    var trip_num = '{$trip_num}';
    var price_num = '{$price_num}';
    var buy_num = '{$buy_num}';
    $(function () {
        var trip_add = 0;
        $("#form1").submit(function () {
            if ($(":text[name='dest_id']").val() == '') {
                Tip.focus("dest_id", "请填写线路所属目的地!");
                return false;
            }
            if ($(":text[name='tag']").val() == '') {
                Tip.focus("tag", "请填写标签!");
                return false;
            }
            if ($(":text[name='name']").val() == '') {
                Tip.focus("name", "请填写线路名称!");
                return false;
            }
            if ($(":text[name='price']").val() == '') {
                Tip.focus("price", "请填写线路价格!");
                return false;
            }
            if ($(":text[name='thumb']").val() == '') {
                Tip.focus("thumb", "请填上传缩略图!");
                return false;
            }
            if ($(":text[name='intro']").val() == '') {
                Tip.focus("intro", "请填写简要说明!");
                return false;
            }
            return true;
        });
    });

    function addProduct() {
        var html = '<div class="form-group" id="product_title_'+trip_num+'">\n' +
            '                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">\n' +
            '                        行程标题\n' +
            '                    </label>\n' +
            '                    <div class="col-sm-9 col-xs-12">\n' +
            '                        <input type="text" name="product[trip]['+trip_num+'][trip_title]" class="form-control"/>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="form-group" id="product_desc_'+trip_num+'">\n' +
            '                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">\n' +
            '                        行程描述\n' +
            '                    </label>\n' +
            '                    <div class="col-sm-8 col-xs-12">\n' +
            '                        <textarea style="height:100px;" class="form-control" name="product[trip]['+trip_num+'][trip_desc]"\n' +
            '                                  cols="100"></textarea>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="form-group col-sm-12" id="product_button_'+trip_num+'">\n' +
            '                    <button class="btn btn-danger col-sm-offset-2" type="button" onclick="delProduct('+trip_num+');">\n' +
            '                        删除行程\n' +
            '                    </button>\n' +
            '                </div>' +
            '</div>';
        $('#addProduct').before(html);
        trip_num++;
    }

    function delProduct(index) {
        $('#product_title_'+index).remove();
        $('#product_desc_'+index).remove();
        $('#product_button_'+index).remove();
    }

    function addPrice() {
        var html = '<div class="form-group" id="price_title_'+price_num+'">\n' +
            '                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">\n' +
            '                        费用标题\n' +
            '                    </label>\n' +
            '                    <div class="col-sm-9 col-xs-12">\n' +
            '                        <input type="text" name="price[price]['+price_num+'][price_title]" class="form-control"/>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="form-group" id="price_desc_'+price_num+'">\n' +
            '                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">\n' +
            '                        费用描述\n' +
            '                    </label>\n' +
            '                    <div class="col-sm-8 col-xs-12">\n' +
            '                        <textarea style="height:100px;" class="form-control" name="price[price]['+price_num+'][price_desc]"\n' +
            '                                  cols="100"></textarea>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="form-group col-sm-12" id="price_button_'+price_num+'">\n' +
            '                    <button class="btn btn-danger col-sm-offset-2" type="button" onclick="delPrice('+price_num+');">\n' +
            '                        删除费用\n' +
            '                    </button>\n' +
            '                </div>' +
            '</div>';
        $('#addPrice').before(html);
        price_num++;
    }

    function delPrice(index) {
        $('#price_title_'+index).remove();
        $('#price_desc_'+index).remove();
        $('#price_button_'+index).remove();
    }

    function addBuy() {
        var html = '<div class="form-group" id="buy_title_'+buy_num+'">\n' +
            '                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">\n' +
            '                        购买标题\n' +
            '                    </label>\n' +
            '                    <div class="col-sm-9 col-xs-12">\n' +
            '                        <input type="text" name="buy[buy]['+buy_num+'][buy_title]" class="form-control"/>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="form-group" id="buy_desc_'+buy_num+'">\n' +
            '                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">\n' +
            '                        购买描述\n' +
            '                    </label>\n' +
            '                    <div class="col-sm-8 col-xs-12">\n' +
            '                        <textarea style="height:100px;" class="form-control" name="buy[buy]['+buy_num+'][buy_desc]"\n' +
            '                                  cols="100"></textarea>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="form-group col-sm-12" id="buy_button_'+buy_num+'">\n' +
            '                    <button class="btn btn-danger col-sm-offset-2" type="button" onclick="delBuy('+buy_num+');">\n' +
            '                        删除购买\n' +
            '                    </button>\n' +
            '                </div>' +
            '</div>';
        $('#addBuy').before(html);
        buy_num++;
    }

    function delBuy(index) {
        $('#buy_title_'+index).remove();
        $('#buy_desc_'+index).remove();
        $('#buy_button_'+index).remove();
    }
</script>
{/if}
{template 'common/footer'}